<!DOCTYPE html>
<html>
<head>
  <title>模版管理 - {$sys_config['site_name']}</title>
  {include file="public/head" /}

  <style>
    input[type="checkbox"] {
      display: none;
    }
    input[type="checkbox"] + label {
      display: inline-block;
      width: 40px;
      height: 20px;
      position: relative;
      -webkit-transition: 0.3s;
      transition: 0.3s;
      margin: 0px 20px;
      box-sizing: border-box;
    }
    input[type="checkbox"] + label:after {
      content: '';
      display: block;
      position: absolute;
      left: 0px;
      top: 0px;
      width: 20px;
      height: 20px;
      -webkit-transition: 0.3s;
      transition: 0.3s;
      cursor: pointer;
    }

    .simple:checked + label.green {
      background: #AEDCAE;
    }

    .simple:checked + label.green:after {
      background: #5CB85C;
    }

    .simple:checked + label:after {
      left: calc(100% - 20px);
    }

    .simple + label {
      background: #ddd;
      border-radius: 20px;
      box-shadow: 1px 1px 3px #aaa;
    }

    .simple + label:after {
      background: #fff;
      border-radius: 50%;
      box-shadow: 1px 1px 3px #aaa;
    }
  </style>
</head>
<body class="hold-transition skin-blue sidebar-mini fixed">
<div class="wrapper">

  {include file="public/nav" /}
  {include file="public/menu" /}

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        模版管理
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 控制台</a></li>
        <li class="active">模版管理</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content container-fluid">

      <div class="row" >
        <div class="col-xs-12">
            <!-- /.box-header -->
          <div class="box">
            <div class="box-body">
              <table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>操作</th>
                  <th>ID</th>
                  <th>模版编号</th>
                  <th>主图</th>
                  <th>所属分类</th>
                  <th>价格</th>
                  <th>属性</th>
                  <th>是否发布</th>
                  <th>来源</th>
                  <th>发布时间</th>
                  <th>浏览量</th>
                  <th>销售量</th>
                </tr>
                </thead>
                <tbody>
                
                <tr>
                  <td colspan="100"><small class="btn btn-primary btn-xs open_mould_box" menu-id="0"><i class="fa fa-plus"></i> 添加模版</small></td>
                </tr>
                {foreach name="list" item="mould"}
                <tr>
                  <td>
                    <small class="btn btn-primary btn-xs open_mould_box" mould-id="{$mould.id}"><i class="glyphicon glyphicon-edit"></i> 编辑</small>
                    <small class="btn btn-danger btn-xs del_menu" mould-id="{$mould.id}"><i class="fa fa-clock-o"></i> 删除</small></td>
                  <td>{$mould.id}</td>
                  <td>{$mould.number}</td>
                  <td width="150"><img style="width: 100%;" src="/{$mould.images}" /></td>
                  <td>{$mould.category.category}</td>
                  <td>{$mould.price}</td>
                  <td>{$mould.attribute}</td>
                  <td><input type="checkbox" {$mould.is_sale==1?'checked':''}  mould-id="{$mould.id}" id="simple_{$mould.id}" class="simple">
                    <label for="simple_{$mould.id}" class="green"></label></td>
                  <td>{$mould.source}</td>
                  <td>{$mould.add_time|date='Y-m-d h:i',###}</td>
                  <td>{$mould.visit}</td>
                  <td>{$mould.sales}</td>
                </tr>
                {/foreach}
                </tbody>
              </table>
              <div class="pull-right">{$page}</div>
            </div>

            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
      </div>
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->

  {include file="public/foot" /}
</div>
<!-- ./wrapper -->
{include file="public/js" /}
<script type="text/javascript">
//根据需要填写需要的模块
layui.use('layer', function(){
  //弹出添加修改
    $('.open_mould_box').click(function() {
       var id = $(this).attr('mould-id');
        layer.open({
            type:2,
            shift:-1,
            title:'模版表单',
            btn: ['确认提交', '取消'],
            area: ['60%', '80%'],
            content: "{:url('Mould/add_mould')}?id="+id,
            yes: function (index, layero) {
                var iframeWin          = window[layero.find('iframe')[0]['name']];
                var menu_data = iframeWin.confirm();
                $.post("{:url('Mould/save_data')}", menu_data,function(res){
                    if (res.status==1){
                        layer.msg(res.msg,{time:2000});
                            location.reload();
                            return false;
                    }else{
                        layer.msg(res.msg,{time:2000});
                        return false;
                    }
                }, "json");
            }
        });
    });

    //删模版
  $('.del_menu').click(function () {
    var id = $(this).attr('mould-id');
    layer.confirm('确定删除此模版吗',{
      btn: ['确定','取消'] //按钮
      }, function(){
        $.post("{:url('Mould/delMould')}", {id:id},function(res){
              if (res.status==1){
                layer.msg(res.msg,{time:1000},function(index, layero){
                  location.reload();
                });
                return false;
              }else{
                layer.msg(res.msg,{time:1000});
                return false;
              }
        }, "json");

      });

  });

  $('.simple').click(function () {
      var id=$(this).attr('mould-id');
      var sale_value=0;
      if($(this).is(':checked')){
          sale_value=1;
      }
      $.post("{:url('Mould/setSale')}", {id:id,sale_value:sale_value},function(res){
          if (res.status==0){
              layer.msg(res.msg,{time:1000},function(){
                  location.reload();
              });
              return false;
          }
      }, "json");
  });


});
</script>
</body>
</html>